home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1997 August / Walnut Creek CDROM.7z / VOL_400 / 446_01 / DOC / FDMSTART / EX6 / CONSLAW.C < prev    next >
Encoding:
C/C++ Source or Header  |  1996-04-18  |  1.5 KB  |  58 lines

  1. #include <ConsLaw.h>
  2. #include <createHCLSchemes.h>
  3. #include <DrawFD.h>
  4.  
  5. real start1 (const Ptv(real)& x, real t) { return 0.0; }
  6. real linearFlux (real u) { return u; }
  7.  
  8. void ConsLaw:: solveProblem ()
  9. {
  10.   setIC ();      // set initial conditions
  11.   timeLoop ();   // perform time stepping
  12. }
  13.  
  14. void ConsLaw:: setIC ()  // initial conditions
  15. { u_prev() = start1; }
  16.  
  17. void ConsLaw:: scan (Is is)
  18. {
  19.   f = linearFlux;
  20.  
  21.   grid.rebind (new GridLattice(1));  grid->scan (is);
  22.   u.rebind (new FieldFD (grid(), "u"));  
  23.   u_prev.rebind (new FieldFD (grid(), "u_prev"));
  24.   const real uL = 1;  u->valueIndex(0) = u_prev->valueIndex(0) = uL;
  25.   tip.scan (is);
  26.   file.open (CaseName);
  27.   time_points_for_plot.scan (is);
  28.   is >> scheme_tp; // scheme type:
  29.   scheme.rebind (createHCLSchemes (scheme_tp, *this));
  30.  
  31.   // write input data for a check:
  32.   u->grid().print(s_o);  tip.print(s_o);
  33.   s_o << "time points for plot: "; time_points_for_plot.print (s_o);
  34. }
  35.  
  36. void ConsLaw:: timeLoop ()
  37. {
  38.   tip.initTimeLoop();
  39.   while (!tip.finished()) {
  40.     tip.increaseTime();
  41.     scheme->update ();
  42.     saveResults ();
  43.     updateDataStructures ();
  44.   }
  45. }
  46.  
  47. void ConsLaw:: saveResults ()
  48. {
  49.   // dump plot data values on file casename.pl if any given point of
  50.   // time for plotting is within 0.5*dt from the present time value:
  51.  
  52.   if (time_points_for_plot.within (tip.getTime(), 0.4999*tip.Delta()))
  53.     DrawFD::makeCurvPlot (u(),file,"u(x) for t fixed","u",
  54.               oform("t=%g",tip.getTime()));
  55. }
  56.  
  57. void ConsLaw:: updateDataStructures ()  { u_prev() = u(); }
  58.